import axios from 'axios'

axios.defaults.baseURL = 'http://localhost:8080/'

axios.interceptors.request.use(
  function (config) {
    let loginToken = sessionStorage.getItem("token");
    if (loginToken) {
      config.headers.token = loginToken;
    }
    return config;
  }
);

axios.interceptors.response.use(
	function (response) {
		//未登录现状
		if (response.data.status == 401) {
			if (sessionStorage.getItem("token")) {
				sessionStorage.removeItem("token")
				console.error("登录已失效，请重新登录")//提示信息
				location.reload();
			} else {
				console.warn("未登录无权限，请登录")//提示信息
			}
		}
    return response;
  }
);

export default axios